package com.xxx.sso.util;

import com.xxx.sso.consts.RedisConst;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * Redis 操作工具类
 * @author caiwl
 * @date 2020/5/7 14:29
 */
@Deprecated
public class RedisUtil {
    /**
     * 设置key值和过期时间
     * @param redisTemplate
     * @param key
     * @param value
     */
    public static void setValue(StringRedisTemplate redisTemplate, String key, String value) {
        redisTemplate.opsForValue().set(key, value, RedisConst.TIMEOUT, TimeUnit.MINUTES);
    }

    /**
     * 获取key值
     * @param redisTemplate
     * @param key
     * @return
     */
    public static String getValue(StringRedisTemplate redisTemplate, String key) {
        return redisTemplate.opsForValue().get(key);
    }

    /**
     * 设置过期时间
     * @param redisTemplate
     * @param key
     */
    public static void expire(RedisTemplate redisTemplate, String key) {
        redisTemplate.expire(key, RedisConst.TIMEOUT, TimeUnit.MINUTES);
    }

    /**
     * 删除指定key
     * @param redisTemplate
     * @param key
     * @return
     */
    public static boolean delete(RedisTemplate redisTemplate, String key) {
        return redisTemplate.delete(key);
    }
}
